import CryptoJS from 'crypto-js'
export function getRandomHexColor() {
    var color = '#' + Math.floor(Math.random() * 16777215).toString(16);
    return color;
  }
  
export  function getContrastColor(color:any) {
    var r = parseInt(color.substring(1, 3), 16);
    var g = parseInt(color.substring(3, 5), 16);
    var b = parseInt(color.substring(5, 7), 16);
    var yiq = (r * 299 + g * 587 + b * 114) / 1000;
  
    var contrastColor = yiq >= 128 ? '#000000' : '#ffffff';
    return contrastColor;
  }

  

  // 加密
export const encryData = (data:any) => {
  let key = 'luox'
  data = encodeURIComponent(CryptoJS.AES.encrypt(JSON.stringify(data), key).toString())
  return data
}
  // 解密
export const decryData = (data:any) => {
  data = decodeURIComponent(data)
  let key = 'luox'
  data = CryptoJS.AES.decrypt(data, key).toString(CryptoJS.enc.Utf8)
  return JSON.parse(data)
}

//定义一个函数判断是手机端还是pc端
export const isMobile = () => {
  if(window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
  return true; // 移动端
  }else{
  return false; // PC端
  }
  }
  